package unify.data;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;

import unify.gui.SysTrayIcon;


import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "feed")
public class Feed {
	@SuppressWarnings("unused")
	@DatabaseField(generatedId = true)
	private int databaseId;
	@DatabaseField
	private String label;
	@DatabaseField
	private String link;
	@DatabaseField
	private int priority;
	@SuppressWarnings("unused")
	@DatabaseField(foreign = true, foreignAutoRefresh=true, foreignAutoCreate=true)
	private Settings settings = Settings.getInstance();
	private final static Logger LOGGER = Logger.getLogger(SysTrayIcon.class.getName());
	
	/**
	 * Ormlite no-arg constructor
	 */
	public Feed() {
		super();
	}
	
	public Feed(String label, String link, int priority) {
		super();
		this.label = label;
		this.link = link;
		this.priority = priority;
	}
	
	public String getLabel() {
		return label;
	}
	
	public void setLabel(String label) {
		this.label = label;
	}
	
	public URL getLink() {
		URL link = null;
		try {
			link = new URL(this.link);
		} catch (MalformedURLException e) {
			LOGGER.severe("Malformed URL: " + e.toString());
			System.exit(1);
		}
		return link;
	}
	
	public void setLink(String link) {
		this.link = link;
	}
	
	public int getPriority() {
		return priority;
	}
	
	public void setPriority(int priority) {
		this.priority = priority;
	}
}
